/*
 *  Copyright (C) void Team 2010 Pedro Batista
 * 
 *  http://code.google.com/p/capacitec
 * 
 *  This file is part of capacitec.
 * 
 *  capacitec is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  capacitec is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with capacitec.  If not, see <http://www.gnu.org/licenses/>.
 */

package dao;

import br.com.caelum.vraptor.ioc.Component;
import entidades.Erro;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;


/**
 *
 * @author pedro
 */
@Component
public class ErroDao {

	private Session session;

	/**
	 *
	 * @param session
	 */
	public ErroDao(Session session) {
		this.session = session;
	}

	/**
	 * Adiciona um novo erro no banco de dados.
	 * @param erro erro a ser adicionado no banco de dados.
	 */
	public void salva(Erro erro) {
		Transaction tx = session.beginTransaction();
		session.save(erro);
		tx.commit();
	}

	/**
	 * Busca no banco de dados o erro com o id e o retorna.
	 * @param id id do erro a ser buscado.
	 * @return Aluno encontrado.
	 */
	public Erro carrega(Long id) {
		Erro erro;
		erro = (Erro) session.load(Erro.class, id);
		return erro;
	}

	/**
	 * Carrega todos os erros encontrados no banco de dados.
	 * @return Lista com os erros encontrados.
	 */
	public List<Erro> carrega() {
		return session.createCriteria(Erro.class).list();
	}

	/**
	 * Recarrega os dados do erro erro, se neste estiver setado o id.
	 * @param erro
	 */
	public void recarrega(Erro erro) {
		session.refresh(erro);
	}

}
